package com.neuedu.controller;

import com.neuedu.model.UserCollection;
import com.neuedu.service.UserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userCollection")
public class UserCollectionController {

    @Autowired
    private UserCollectionService userCollectionService;

    /**
     * 添加收藏
     * @param userCollection 收藏信息实体
     * @return 添加结果
     */
    @PostMapping("/add")
    public String addCollection(@RequestBody UserCollection userCollection) {
        boolean result = userCollectionService.addCollection(userCollection);
        if (result) {
            return "收藏添加成功";
        } else {
            return "收藏添加失败";
        }
    }

    /**
     * 根据用户 ID 查询收藏列表
     * @param uid 用户 ID
     * @return 收藏列表
     */
    @GetMapping("/query/{uid}")
    public List<UserCollection> queryCollectionsByUid(@PathVariable("uid") Integer uid) {
        return userCollectionService.queryCollectionsByUid(uid);
    }

    /**
     * 根据收藏记录 ID 删除收藏
     * @param collectionId 收藏记录 ID
     * @return 删除结果
     */
    @DeleteMapping("/delete/{collectionId}")
    public String deleteCollection(@PathVariable("collectionId") Integer collectionId) {
        boolean result = userCollectionService.deleteCollection(collectionId);
        if (result) {
            return "收藏删除成功";
        } else {
            return "收藏删除失败";
        }
    }
}